/**
 * @author 徐楠
 * @date 2022/4/8 21:50
 * @version 1.0
 */

package com.xunan.likou;

public class RotateImage {
    public static void main(String[] args) {
        int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        rotate(matrix);
        System.out.println();
        for (int[] ints : matrix) {
            for (int anInt : ints) {
                System.out.print(anInt + " ");
            }
            System.out.print("  ");
        }
        System.out.println();
    }

    public static void rotate(int[][] matrix) {
        //列长
        int x = matrix.length;
        int[][] result = new int[x][x];


        int n = x - 1;
        int i = 0;
        while (0 <= n) {
            int m = 0;
            for (int j = 0; j < x; j++) {
                result[m][n] = matrix[i][j];
                m++;
            }

            i++;
            n--;

        }

        for (int j = 0; j < x; j++) {
            for (int k = 0; k < x; k++) {
                matrix[j][k] = result[j][k];
            }
        }

    }
}
